<template>
  <div class="nav-header">
    <div class="fold-menu">
      <el-icon size="30px" @click="handleFoldClick"
        ><Fold v-if="!isFold" /><Expand v-else
      /></el-icon>
    </div>
    <div class="content">
      <Nav-breadcrumb :breadcrumbs="breadcrumbs" />
      <User-info />
    </div>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, ref } from 'vue'
import NavBreadcrumb from '@/base-ui/breadcrumb'
import UserInfo from './user-info.vue'
import { pathMapBreadcrumbs } from '@/utils/map-menus'
import { useStore } from '@/store'
import { useRoute } from 'vue-router'

export default defineComponent({
  emits: ['foldChange'],
  components: { UserInfo, NavBreadcrumb },
  setup(props, { emit }) {
    const isFold = ref(false)
    const handleFoldClick = () => {
      isFold.value = !isFold.value
      emit('foldChange', isFold.value)
    }

    //store
    const store = useStore()
    const route = useRoute()
    //面包屑数据 [{name, path}]
    const breadcrumbs = computed(() => {
      return pathMapBreadcrumbs(store.state.login.userMenus, route.path)
    })
    return { isFold, handleFoldClick, breadcrumbs }
  }
})
</script>

<style lang="less" scoped>
.nav-header {
  display: flex;
  width: 100%;
  .fold-menu {
    margin-left: 10px;
    cursor: pointer;
  }
  .content {
    // width: 100%;
    display: flex;
    flex: 1;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
  }
}
</style>
